package com.woniu.controller;

import com.woniu.Result;
import com.woniu.pojo.Circle;
import com.woniu.service.ICircleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dong
 * @since 2022-11-17
 */
@RestController
@RequestMapping("/circle")
@Api(tags = "车友圈模块")
public class CircleController {

    @Autowired
    private ICircleService circleService;

    @ApiOperation("发布车友圈")
    @PostMapping("/user-auth/save")
    public Result<String> saveCircle(@RequestBody Circle circle, HttpServletRequest request){
        String userId1 = request.getHeader("userId");
        int userId = Integer.parseInt(userId1);
        Result<String> result = circleService.saveCircle(circle, userId);
        return result;
    }


    @ApiOperation("删除车友圈")
    @DeleteMapping("/user-auth/remove/{id}")
    public Result<String> removeCircle(@PathVariable Integer id, HttpServletRequest request){
        String userId1 = request.getHeader("userId");
        int userId = Integer.parseInt(userId1);
        Result<String> result = circleService.removeCircle(id, userId);
        return result;
    }
}
